﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using CrystalDecisions.Shared;

namespace Quanlybanhang
{
    public partial class MuavaoReportForm : Office2007Form
    {
        public MuavaoReportForm()
        {
            InitializeComponent();
            dataGridView1.Hide();
        }

        public String khachhang { set; get; }
        public String diachi { set; get; }
        public String tongcong { get; set; }
        public String nocu { set; get; }
        public String datra { set; get; }
        public String conlai { set; get; }
        public String ngaythang { set; get; }
        public DataTable dt { get; set; }

        private void ReportForm_Load(object sender, EventArgs e)
        {
            MuavaoReport muarp = new MuavaoReport();
            MuavaoForm mv = new MuavaoForm();

            dataGridView1.DataSource = dt;

            int numrow = mv.dataGridViewX1.RowCount - 1;
            MuavaoDS ds = new MuavaoDS();
            DataTable t = ds.Tables.Add("Items");

            t.Columns.Add("tenhang", Type.GetType("System.String"));
            t.Columns.Add("soluong", Type.GetType("System.String"));
            t.Columns.Add("dongia", Type.GetType("System.String"));
            t.Columns.Add("thanhtien", Type.GetType("System.String"));
            t.Columns.Add("chuhang", Type.GetType("System.String"));
            t.Columns.Add("diachi", Type.GetType("System.String"));
            t.Columns.Add("tongcong", Type.GetType("System.String"));
            t.Columns.Add("nocu", Type.GetType("System.String"));
            t.Columns.Add("datra", Type.GetType("System.String"));
            t.Columns.Add("conlai", Type.GetType("System.String"));
            t.Columns.Add("ngaythang", Type.GetType("System.String"));

            DataRow r;
            r = t.NewRow();
            r["Chuhang"] = khachhang;
            r["Diachi"] = diachi;
            t.Rows.Add(r);

            for (int i = 0; i < numrow; i++)
            {
                r = t.NewRow();
                r["tenhang"] = dataGridView1.Rows[i].Cells[0].FormattedValue.ToString();
                r["soluong"] = dataGridView1.Rows[i].Cells[1].FormattedValue.ToString();
                r["dongia"] = dataGridView1.Rows[i].Cells[2].FormattedValue.ToString();
                r["thanhtien"] = dataGridView1.Rows[i].Cells[3].FormattedValue.ToString();
                t.Rows.Add(r);
            }

            r = t.NewRow();
            r["Tongcong"] = tongcong;
            r["Nocu"] = nocu;
            r["Datra"] = datra;
            r["Conlai"] = conlai;
            r["Ngaythang"] = ngaythang;
            t.Rows.Add(r);

            muarp.SetDataSource(ds.Tables[1]);

            //Dua du lieu tu datagridview vao report
            crystalReportViewer1.ReportSource = muarp;
        }
    }
}
